home *** CD-ROM | disk | FTP | other *** search
- package sub_arctic.lib;
-
- import sub_arctic.input.*;
- import sub_arctic.output.*;
- import sub_arctic.constraints.constraint;
-
- import java.awt.Font;
- import java.awt.FontMetrics;
-
- /**
- * This is just a little object which makes labels have a callback and
- * keep track of their state. Its useful in things like menus and what
- * not when someone else needs to stay informed of state changes.
- * This object sends a callback to its callback object with
- * a boolean as the info indicating its new state.<p>
- *
- * This object allows its width to be anything the parent (or anyone
- * else) wishes (unlike more traditional labels).
- *
- * @author Ian Smith
- */
- public class press_label extends label implements pressable {
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Keep track of the active state.
- */
- protected boolean _active;
-
- /**
- * Return whether the object is active or not.
- * @return int true if the object is active
- */
- public boolean active() { return _active;};
-
- /**
- * Make the active state the opposite of what it is now.
- */
- public void invert_active() {
- /* invert the state of active */
- if (active()) {
- _active=false;
- } else {
- _active=true;
- }
- /* invert the display */
- set_draw_colors(draw_colors().inverted());
- }
-
- /**
- * Set the active state to either true or false.
- * @param boolean b the new active state
- */
- public void set_active(boolean b) {
- if (active()!=b) {
- invert_active();
- }
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * The object to whom we are sending our callback.
- */
- protected callback_object _callback_obj;
-
- /**
- * Access the current callback object.
- * @return callback_object the object to whom we are sending callbacks.
- */
- public callback_object callback_obj() { return _callback_obj;};
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
-
- /**
- * Construct a new press_label.
- * @param String s the string to display in the label.
- * @param boolean opacity true if the object should be opaque (paint
- * its background).
- * @param callback_object obj the object to send the callback's to.
- */
- public press_label(String s, Font f, boolean opacity, callback_object obj) {
-
- super(s,f);
-
- /* do we want opacity */
- set_opaque(opacity);
-
- /* initially we are not active */
- _active=false;
-
- /* set the callback object to the passed in one */
- _callback_obj=obj;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /** Callback number constant for callbeack when we are pressed. */
- public static final int LABEL_ACTION_CALLBACK = 0;
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Respond to the press method from the agent. This object generates
- * its callback on the <I>press</I> not on a matched pair of
- * press and release.
- *
- * @param event evt the press event (usually mouse down).
- * @param Object user_info the object passed the pick_collector at pick-time.
- * @return boolean true if we consumed the event
- */
- public boolean press(event evt, Object user_info) {
-
- /* invert our state */
- invert_active();
-
- if (callback_obj()!=null) {
- /* just tell the other code what happened */
- callback_obj().callback(this,evt,LABEL_ACTION_CALLBACK,
- new Boolean(active()));
- }
-
- /* we took it */
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Respond to the release method from the agent.
- * @param event evt the press event (usually mouse up).
- * @param Object user_info the object passed the pick_collector at pick-time.
- * @return boolean true if we consumed the event
- */
- public boolean release(event evt, Object user_info) {
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Respond to questions about how wide our string is.
- * @return int the number of pixels wide the string is (plus twice the
- * horizontal spacing to take into account the borders on left
- * and right).
- */
- public int string_width() {
- String s=text();
- FontMetrics metrics=manager.get_metrics(font());
-
- /* ok compute the string size + 2 times the border */
- int w=metrics.stringWidth(s)+(2*_h_spacing);
-
- return w;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Fake out our superclass with a new implementation of
- * intrinsic constraints which returns only a height constraint.
- * We don't have a intrinsic width because we are going to be
- * flexible about putting ourselves in any width requested
- * by the parent.
- *
- * @return int the constant for an intrinsic constraint on width
- */
- public int intrinsic_constraints() {
- return interactor_consts.H; /* we have an intrinsic height but not width */
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-